//
//  HXQuestionTableViewCell.m
//  KD
//
//  Created by Hubery on 16/2/2.
//  Copyright © 2016年 ifly. All rights reserved.
//

#import "HXQuestionTableViewCell.h"

@interface HXQuestionTableViewCell()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextField *textFeild;
@property(nonatomic,strong) UIToolbar  *keyboardDoneButtonBar;
@end

@implementation HXQuestionTableViewCell


- (void)awakeFromNib{
    self.textFeild.delegate = self;
    self.textFeild.inputAccessoryView = self.keyboardDoneButtonBar;
}

- (void)setRow:(int)row{
    _row = row;
    self.label.text = [NSString stringWithFormat:@"问题%d:",row+1];
    self.textFeild.tag = row;
}

- (void)setQuestionMessage:(NSString *)questionMessage
{
    _questionMessage = questionMessage;
    self.textFeild.text = questionMessage;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (![textField.text isEqualToString:@"'"]) {
        [self.delegate questionMessage:textField.text row:textField.tag];
    }
}

-(UIToolbar*)keyboardDoneButtonBar{
    if(!_keyboardDoneButtonBar){
        _keyboardDoneButtonBar= [[UIToolbar alloc] init];
        _keyboardDoneButtonBar.barStyle = UIBarStyleDefault;
        _keyboardDoneButtonBar.tintColor = nil;
        [_keyboardDoneButtonBar sizeToFit];
        UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                                  target:nil
                                                                                  action:nil];
        UIButton *okBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [okBtn addTarget:self action:@selector(DoneClicked:) forControlEvents:UIControlEventTouchUpInside];
        okBtn.size = CGSizeMake(44, 44);
        [okBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [okBtn setTitle:@"确定" forState:UIControlStateNormal];
        okBtn.titleLabel.textColor = [UIColor blueColor];
        UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithCustomView:okBtn];
        [_keyboardDoneButtonBar setItems:[NSArray arrayWithObjects:flexItem,doneButton, nil]];
        
    }
    return _keyboardDoneButtonBar;
}
-(void)DoneClicked:(UIButton *)btn{
    
    [self endEditing:YES];
}

@end
